//
//  HTCoverView.swift
//  MagaCore
//
//  Created by MrMessy on 2023/5/4.
//

import SDWebImageSwiftUI
import SwiftUI

struct HTCoverView: View {
    var var_anime: HTAnime = HTAnime()

    var var_showVIP: Bool = false
    var var_showCAM: Bool = false
    var var_showDUB: Bool = false
    var var_showAdded: Bool = false
    var var_cornerRadius: CGFloat = UIDevice.ht_fixToWidth(width: 6)
    var var_width: CGFloat = UIDevice.ht_fixToWidth(width: 108)
    var var_height: CGFloat = UIDevice.ht_fixToWidth(width: 160)

    var body: some View {
        ZStack(alignment: .top) {
            WebImage(url: URL(string: var_anime.var_cover ?? ""))
                .resizable()
                .indicator(.activity)
                .transition(.fade(duration: 0.5))
                .frame(maxWidth: .infinity, maxHeight: .infinity)
            VStack {
                HStack {
                    if var_anime.var_age == "1" {
                        Image("18+")
                            .frame(width: UIDevice.ht_fixToWidth(width: 30), height: UIDevice.ht_fixToWidth(width: 18))
                    }

                    Spacer()

                    if var_showCAM {
                        HStack {
                            Text("CAM")
                                .font(.system(size: UIDevice.ht_fixToWidth(width: 10)))
                                .fontWeight(.bold)
                        }
                        .frame(width: UIDevice.ht_fixToWidth(width: 38), height: UIDevice.ht_fixToWidth(width: 16))
                        .background(Color.white)
                        .cornerRadius(UIDevice.ht_fixToWidth(width: 2))
                        .offset(x: UIDevice.ht_fixToWidth(width: -6), y: UIDevice.ht_fixToWidth(width: 6))
                    }

                    if var_anime.var_dub == "1" && var_showDUB {
                        HStack {
                            Text("DUB")
                                .font(.system(size: UIDevice.ht_fixToWidth(width: 10)))
                                .foregroundColor(Color.white)
                        }
                        .frame(width: UIDevice.ht_fixToWidth(width: 38), height: UIDevice.ht_fixToWidth(width: 16))
                        .background(Color(hex: "#4F40BD"))
                        .cornerRadius(UIDevice.ht_fixToWidth(width: 2))
                        .offset(x: UIDevice.ht_fixToWidth(width: -6), y: UIDevice.ht_fixToWidth(width: 6))
                    }
                }
                Spacer()

                ZStack(alignment: .trailing) {
                    Image("cover_gradient")
                        .ht_resizeToFit()
                    Text(var_anime.var_ep ?? "")
                        .font(.system(size: UIDevice.ht_fixToWidth(width: 10)))
                        .foregroundColor(.white)
                        .offset(x: UIDevice.ht_fixToWidth(width: -6))
                }
                .frame(maxWidth: .infinity, alignment: .leading)
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
        }
        .frame(width: var_width, height: var_height)
        .cornerRadius(var_cornerRadius)
        .clipped()
    }
}
